using System;
using System.Drawing;
using System.Collections.Generic;
using System.Text;

namespace CallerID.Helpers
{
    public class DrawingHelpers
    {
        /// <summary>
        /// Creates StringFormat from specified parameters.
        /// </summary>
        public static StringFormat CreateStringFormat(ContentAlignment textAlign, bool wrapText, bool showEllipsis, bool rightToLeft)
        {
            StringFormat format = new StringFormat();
            format.Alignment = EnumHelpers.ContentAlignmentToStringAlignment(textAlign, false);
            format.LineAlignment = EnumHelpers.ContentAlignmentToStringAlignment(textAlign, true);
            if(!wrapText) format.FormatFlags |= StringFormatFlags.NoWrap;
            if(showEllipsis) format.Trimming = StringTrimming.EllipsisCharacter;
            if(rightToLeft) format.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
            return format;
        }

        public static Icon GetIcon(Image image)
        {
            Icon icon = null;
            if(image != null) {
                Bitmap bitmap = new Bitmap(image);
                icon = Icon.FromHandle(bitmap.GetHicon());
                bitmap.Dispose();
            }
            return icon;
        }
    }
}
